var serviceHttp = 'http://www.ihengtian.top:8101/';

// var shop_before = '/api/cft/shop';
var query_mine_info = '/query/mine/info';

var organ_before = '/api/cft/organ';
var query_job_level = '/shop/job/level/config';
var query_stuff='/query/below/stuffs';
var insert_sturff='/insert/mine/stuff';

var indexApp = angular.module('stuffApp', []);


indexApp.controller("stuffCtrl", function($http, $scope, $location) {
    function GetRequest() {
        var url = location.search; 
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    var Req = new Object();
    Req = GetRequest();

    var currentToken = Req["token"];
    var shopId = Req["shopId"];

    $http({  
    	method:'post',  
   		url:serviceHttp + organ_before + query_mine_info,  
    	data:{token:currentToken}  
		}).success(function(response){  
			$scope.mine = response.data;
    		console.log(response);  
		})  
	
	$http({  
    	method:'post',  
   		url:serviceHttp + organ_before + query_job_level,  
    	data:{token:currentToken}  
		}).success(function(response){  
			$scope.jobs = response.data;
    		console.log(response);  
		})  

    $scope.insertData = {token:currentToken,id:shopId,jobId:"",nickName:"",wechatLoginRequest:{mobile:""}};   

	$scope.insertStuff = function() {
        $http({  
    	method:'post',  
   		url:serviceHttp + organ_before + insert_sturff,  
    	data:$scope.insertData  
		}).success(function(response){  
			$scope.stuff = response.data;
			$scope.message=response.message;
            $scope.insertData = {token:currentToken,id:shopId,jobId:"",nickName:"",wechatLoginRequest:{mobile:""}};   
    		console.log(response);  
		}) 
    };

    $scope.reBack = function(stuff) {
        window.location.href = "index";
    }

});